package com.wsx.sky.dubbo.controller;

import com.wsx.sky.dubbo.bean.DubboResponse;
import com.wsx.sky.dubbo.model.DubboServer;
import com.wsx.sky.dubbo.service.DubboService;
import com.wsx.sky.dubbo.service.MongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangshuaixin
 * @Title: com.wsx.sky.dubbo.controller.DubboController
 * @Description: TODO
 * @date 2018/12/11
 */
@RestController
@RequestMapping("/dubbo/http")
public class DubboController {


    @Autowired
    private MongoService mongoService;


    @RequestMapping(
            value = "/get/save/{name}",
            method = {RequestMethod.GET}
    )
    public DubboResponse http(@PathVariable("name") String name) {
        DubboServer dubboServer = mongoService.getOrSave(name);
        if (null != dubboServer) {
            return new DubboResponse().buildMsg(dubboServer.get_id());
        }
        return new DubboResponse(50001);
    }

    @Autowired
    private DubboService dubboService;

    @RequestMapping(
            value = "/get/dubbo/{name}",
            method = {RequestMethod.GET}
    )
    public DubboResponse dubbo(@PathVariable("name") String name) {
        return dubboService.get(name);
    }
}
